package main

import (
	"crypto/md5"
	"encoding/hex"
	"encoding/json"
	"log"
	"net/http"
	"os"
	"reflect"
)
type Result struct {
	Code int    `json:"code"`
	Resp string `json:"resp"`
}


/**
	@author luckyFang
	@date 2020 10 15
	@desc 工具类
*/



// 转化为 md5
func toMd5(val interface{}) string {
	str := reflect.ValueOf(val).String()
	hash := md5.New()
	hash.Write([]byte(str))
	return hex.EncodeToString(hash.Sum(nil))
}

// 文件是否存在
func fileExists(path string)error  {
	_, err := os.Stat(path)
	if err!=nil {
		return err
	}
	return nil
}

func OutputJson(w http.ResponseWriter, code int, resp string) {
	out := &Result{code, resp}
	b, err := json.Marshal(out)
	if err != nil {
		return
	}
	_, _ = w.Write(b)
}

// banner
func banner(){
	banner:=`  ___                            
 -   -_,             ,, ,,       
(  ~/||              || ||       
(  / ||  -_-_   /'\\ || ||  /'\\ 
 \/==||  || \\ || || || || || || 
 /_ _||  || || || || || || || || 
(  - \\, ||-'  \\,/  \\ \\ \\,/  
         |/           `
	log.Println(banner)
}


